<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;
class DetailsController extends PublicController {
	
    public function detailsAction(){
		
		$id=I('get.id',0,int);
		
		$aid=I('get.aid',0,int);
		$this->assign('aid',$aid);
		
		//读取商品属性
		$attlist=$this->attributelist($id);
		$this->assign('attlist',$attlist);
		//print_r($attlist);die;
		
		//读取热销推荐
		$hlist=$this->getshoplist('hot',$count=5);
		$this->assign('hlist',$hlist);
		
		$Model=D('Goods');
		
		$one=$Model->where(" frame=1 and id=$id ")->relation(true)->find();
		
		
		
		$one['preferential']=$one['atype']?($one['price']*($one['avalue']/10)):($one['price']-$one['avalue']);

		if(empty($one)){
			$this->error('对不起，您访问的页面不存在！');
			}
		$one['content']=htmlspecialchars_decode($one['content']);
		$this->assign('one',$one);
		
		//图片相册
		$imageslist=$this->imageslist($id);
		$this->assign('imageslist',$imageslist);
			

		//读取分类树
		$tree=$this->gettree(0);
		$this->assign('tree',$tree);
		
		$this->view();
	
    }
	
	
	//读取商品属性
	public function attributelist($id){
		
		$GAmodel=D("GoodsNAttribute"); // 实例化GoodsNAttribute对象

		//关联模型查询
		$ablist=$GAmodel->relation('Attri')->where(' goodsid='.$id)->select();		
		$attrlist=array();
		foreach($ablist as $key=>$val){	
			$attrlist[$val['attid']][]=$val;
		}		
		return $attrlist;
		
	}
	
	
	//获取相册图片函数
	public function imageslist($id,$type='goods'){
		$Model=D('Images');
		
		$list=$Model->where(" goodsid=$id and type='$type' ")->order(' sort desc ')->select();
		
		return $list;
		
	}
	
	

	
	
	
}